package com.cloudcc.cloudframe.util;

import java.util.Map;

import android.R.integer;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharePreferece {
	private Context context;

	/**
	 * 文件
	 */
	public static final String DOC_USER = "user";

	public SharePreferece(Context context) {
		this.context = context;
	}

	// 建立偏好设置
	public boolean SaveShare(String filename, Map<String, Object> map) {
		boolean flag = false;
		SharedPreferences sharepre = context.getSharedPreferences(filename,
				Context.MODE_PRIVATE);
		Editor editor = sharepre.edit();
		for (Map.Entry<String, Object> entity : map.entrySet()) {
			String key = entity.getKey();
			Object object = entity.getValue();
			if (object instanceof Boolean) {
				Boolean boolean1 = (Boolean) object;
				editor.putBoolean(key, boolean1);
			} else if (object instanceof Integer) {
				Integer integer = (Integer) object;
				editor.putInt(key, integer);
			} else if (object instanceof String) {
				String string = (String) object;
				editor.putString(key, string);
			} else if (object instanceof Long) {
				Long log = (Long) object;
				editor.putLong(key, log);
			}
		}
		flag = editor.commit();
		return flag;
	}

	// 读取偏好设置
	public Map<String, ?> getShare(String fileName) {

		Map<String, ?> map = null;
		SharedPreferences shares = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		map = shares.getAll();
		return map;
	}

}
